#include <bits/stdc++.h>

using namespace std;
#define int long long
const int M = 200020, N = 5010;
int pre[N];
int n,m;

struct Edge
{
    int a,b,w;
    bool operator <(const Edge& W) const
    {
        return w < W.w;
    }
}edge[M];

int find(int x)
{
    if(x != pre[x]) pre[x] = find(pre[x]);
    return pre[x];
}


int kruskal()
{
    sort(edge,edge + m);
    for(int i = 1; i <= n; i ++)
    {
        pre[i] = i;
    }
    int res = 0;
    int cnt = 0;
    for(int i = 1; i <= m; i ++)
    {
        int a = edge[i].a;
        int b = edge[i].b;
        int w = edge[i].w;              
        if(find(a) != find(b))
        {
            pre[find(a)] = find(b);
            res+=w;
            cnt ++;
        }
    }
    if(cnt < n - 1)
    {
        return -1;
    }
    else return res;
}


signed main()
{
    cin >> n >> m;
    for(int i = 1; i <= m; i ++)
    {
        int a,b,w;
        cin >> edge[i].a >> edge[i].b >> edge[i].w;
    }
    int t = kruskal();
    if(t==-1)
    {
        cout << "orz" << endl;
    }
    else
    {
        cout<<t<<endl;
    }
}